package qlsl.androiddesign.http.service.subservice;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import qlsl.androiddesign.constant.WhatConstant;
import qlsl.androiddesign.entity.commonentity.Pager;
import qlsl.androiddesign.entity.commonentity.User;
import qlsl.androiddesign.entity.otherentity.PoemDynamic;
import qlsl.androiddesign.handler.subhandler.HttpHandler;
import qlsl.androiddesign.http.HttpListener;
import qlsl.androiddesign.http.service.baseservice.BaseService;
import qlsl.androiddesign.thread.HandlerThread;
import qlsl.androiddesign.util.commonutil.PagerUtils;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 诗友动态模块 <br/>
 * 
 */
public class PoemDynamicService extends BaseService {

	private static String className = getClassName(PoemDynamicService.class);

	public static void queryPoemDynamic(final int page, final FunctionView<?> functionView,
			final HttpListener listener) {
		functionView.setProgressBarText("正在查询诗友动态");
		final HttpHandler handler = getHandler(functionView, listener, className, "queryPoemDynamic");
		new HandlerThread(className, "queryPoemDynamic") {
			public void run() {
				try {
					HashMap<String, Object> map = new HashMap<String, Object>();
					List<PoemDynamic> list = new ArrayList<PoemDynamic>();
					String[] typeNames = new String[] { "精选原创", "官方发布" };
					List<String> tags = new ArrayList<String>();
					tags.add("标签1");
					tags.add("标签2");

					for (int index = (15 * page) + 1; index <= 15 * (page + 1); index++) {
						PoemDynamic item = new PoemDynamic();
						User user = new User();
						user.setAvatar(
								"http://bmob-cdn-690.b0.upaiyun.com/2016/04/28/23f69832408d2333808d5e09e49a190d.jpg");
						user.setLevel(index * 3);
						user.setName("用户" + index);
						item.setUser(user);
						item.setPetUrl(
								"http://bmob-cdn-690.b0.upaiyun.com/2016/04/28/1e9673de407f5ef980f0478ebee24c79.jpg");
						item.setCommentNum(index * 10);
						item.setStoreNum(index * 5);
						item.setContent("诗篇" + index + "是一首慷慨激昂的诗词");
						item.setTypeName(index % 2 == 0 ? typeNames[0] : typeNames[1]);
						item.setTags(tags);
						list.add(item);
					}

					Pager pager = PagerUtils.createPager(page, 105);

					map.put("list", list);
					map.put("pager", pager);

					handler.sendMessage(WhatConstant.WHAT_NET_DATA_SUCCESS, map);
				} catch (Exception e) {
					e.printStackTrace();
					handler.sendMessage(WhatConstant.WHAT_EXCEPITON, e);
				}
			};
		}.start();
	}
}
